module led_display_ctrl (
    input wire clk,
	input wire rst_n,
    // input wire wen,
    input wire [31:0] data_in,
	output reg [7:0] led_en,
	output reg led_ca,
	output reg led_cb,
    output reg led_cc,
	output reg led_cd,
	output reg led_ce,
	output reg led_cf,
	output reg led_cg,
	output wire led_dp
);

parameter DIV_CLK = 'd10_000;
reg [23:0] cnt;
reg [3:0] num;

assign led_dp = 1;

//counter, a circle is 0.1ms
always @(posedge clk or negedge rst_n) begin
    if (~rst_n) cnt <= 'b0;
    // else if (button) cnt <= 'b0;
    else if (cnt == DIV_CLK) cnt <= 'b0;
    else cnt <= cnt + 1'b1;
end

//led_en
always @(posedge clk or negedge rst_n) begin
    if (~rst_n) led_en <= 'h7f;
    // else if (button) led_en <= 'h7f;
    else if (cnt == DIV_CLK - 'b1) led_en <= {led_en[0], led_en[7:1]};
    else led_en <= led_en;
end

// display
reg [31:0] display;
always @(*) begin
    display = data_in;
    // if(wen) display = data_in;
    // else display = display;
end

//num
// always @(posedge clk) begin
always @(*) begin
    case (led_en)
        'b11111110: num = display[3:0];
        'b11111101: num = display[7:4];
        'b11111011: num = display[11:8];
        'b11110111: num = display[15:12];
        'b11101111: num = display[19:16];
        'b11011111: num = display[23:20];
        'b10111111: num = display[27:24];
        'b01111111: num = display[31:28];
        default   : num = 'h0;
    endcase
end

//led_cx
// always @(posedge clk) begin
always @(*) begin
    if      (num == 'h0) {led_cg,led_cf,led_ce,led_cd,led_cc,led_cb,led_ca} = 7'b1000000;
    else if (num == 'h1) {led_cg,led_cf,led_ce,led_cd,led_cc,led_cb,led_ca} = 7'b1111001;
    else if (num == 'h2) {led_cg,led_cf,led_ce,led_cd,led_cc,led_cb,led_ca} = 7'b0100100;
    else if (num == 'h3) {led_cg,led_cf,led_ce,led_cd,led_cc,led_cb,led_ca} = 7'b0110000;
    else if (num == 'h4) {led_cg,led_cf,led_ce,led_cd,led_cc,led_cb,led_ca} = 7'b0011001;
    else if (num == 'h5) {led_cg,led_cf,led_ce,led_cd,led_cc,led_cb,led_ca} = 7'b0010010;
    else if (num == 'h6) {led_cg,led_cf,led_ce,led_cd,led_cc,led_cb,led_ca} = 7'b0000010;
    else if (num == 'h7) {led_cg,led_cf,led_ce,led_cd,led_cc,led_cb,led_ca} = 7'b1111000;
    else if (num == 'h8) {led_cg,led_cf,led_ce,led_cd,led_cc,led_cb,led_ca} = 7'b0000000;
    else if (num == 'h9) {led_cg,led_cf,led_ce,led_cd,led_cc,led_cb,led_ca} = 7'b0010000;
    else if (num == 'ha) {led_cg,led_cf,led_ce,led_cd,led_cc,led_cb,led_ca} = 7'b0001000;
    else if (num == 'hb) {led_cg,led_cf,led_ce,led_cd,led_cc,led_cb,led_ca} = 7'b0000011;
    else if (num == 'hc) {led_cg,led_cf,led_ce,led_cd,led_cc,led_cb,led_ca} = 7'b1000110;
    else if (num == 'hd) {led_cg,led_cf,led_ce,led_cd,led_cc,led_cb,led_ca} = 7'b0100001;
    else if (num == 'he) {led_cg,led_cf,led_ce,led_cd,led_cc,led_cb,led_ca} = 7'b0000110;
    else if (num == 'hf) {led_cg,led_cf,led_ce,led_cd,led_cc,led_cb,led_ca} = 7'b0001110;
    else                 {led_cg,led_cf,led_ce,led_cd,led_cc,led_cb,led_ca} = 7'b1111111;
end

endmodule


